<?php
require('config.php');

        $zh=$_REQUEST['zh'];
        $pwd=$_REQUEST['pwd'];
        $time=date('Y-m-d H:i:s');
		$sql="select * from `".$oto."_users` where `userPhone`='{$zh}' and userFlag='1' LIMIT 1";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$pson[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(!isset($pson))
		{
			$data[0]['chenggong']='false';
			$data[0]['msg']='账号不存在';
		}
		else
		{	
			// $data[0]['pwd1']=$pwd;
			$pwd=md5($pwd.$pson[0]['loginSecret']);
			// $data[0]['pwd']=$pwd;
			// $data[0]['loginSecret']=$pson[0]['loginSecret'];
			$sql="select * from `".$oto."_users` where `userPhone`='{$zh}' and loginPwd='{$pwd}' and userFlag='1' LIMIT 1";
			$result=$db->query($sql);
			while($row=$result->fetch_assoc()){
				$yan[]=$row;//将取得的所有数据赋值给person_info数组
			}
			if(!isset($yan))
			{
				$data[0]['chenggong']='-1';
				$data[0]['msg']='密码错误';
			}
			else
			{
				$userId=$pson[0]['userId'];
				$user_id=$pson[0]['userId'];
				$sql="update ".$oto."_users set lastTime='{$time}' where userId='{$userId}'";
				$result=$db->query($sql);
				$yan[0]['chenggong']='true';
				$yan[0]['msg']='登陆成功';
				$data=$yan;

				$sql="select * from `".$oto."_youhui_user_link`,`".$oto."_youhui` where ".$oto."_youhui_user_link.user_id='{$user_id}' and u_is_effect='1' and ".$oto."_youhui_user_link.youhui_id=".$oto."_youhui.id";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$youhui[]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(isset($youhui))
				{
					$sum=0;
					for($i=0;$i<count($youhui);$i++)
					{
						$shop_id=$youhui[$i]['supplier_id'];
						$sql="select shopName,shopImg,goodsCatId1 from `".$oto."_shops` where shopId='{$shop_id}'";
						$result=$db->query($sql);
						while($row=$result->fetch_assoc()){
							$shops[$i][]=$row;//将取得的所有数据赋值给person_info数组
						}
						if(isset($shops[$i]))
						{
							$youhui[$i]['shopName']=$shops[$i][0]['shopName'];
							$youhui[$i]['shopImg']=$shops[$i][0]['shopImg'];
							$youhui[$i]['goodsCatId']=$shops[$i][0]['goodsCatId1'];
						}
						else
						{
							$youhui[$i]['shopName']="";
							$youhui[$i]['shopImg']="";
							$youhui[$i]['goodsCatId']="0";
						}
						$max=$youhui[$i]['surplus'];
						for($j=0;$j<$max;$j++)
						{
							$data2[$sum]=$youhui[$i];
							$sum++;
						}
					}
					$data[0]['youhui_num']=''.count($data2);
				}
				else $data[0]['youhui_num']='0';
			}
		}
		echo json_encode($data);
?>